﻿using System;
using System.Runtime.CompilerServices;

namespace Judge
{
    //out指定的函数会清空自己，必须在函数内部赋初始值
    class Program
    {
        static void Main(string[] args)
        {
            //ref
            //ref将一个变量代入一个方法中，然后将改变的量带出来
            double credit = 101;
            Add(ref credit); 
            Console.WriteLine("学分是：{0}", credit);
            Console.ReadKey();



            //out
            Console.WriteLine("欢迎来到学生登录页面");
            Console.WriteLine("请输入用户名");
            string userName = Console.ReadLine();
            Console.WriteLine("请输入密码");
            string passWord = Console.ReadLine();
            string msg;
            bool res = IsLogin(userName , passWord , out msg);
            Console.WriteLine(res);
            Console.WriteLine(msg);
            Console.ReadKey();


            //params
            //params可变参数，必须是行参列表中的最后一个元素，适用于参数不固定的时候
            Student("Alice",11, 100, 88, 99);
            Console.WriteLine();

            
        }
        //params
        private static int Student(string StudentName, int id, params int[] score)
        {
            int max = score[0];
            for(int i=0; i < score.Length; i++)
            {
                if(max<score[i])
                {
                    max = score[i];
                }
            } 
            Console.WriteLine("名字是{0}，学号是{1}，成绩最高是数学{2}", StudentName, id, max);
            return max;

        }



        //ref
        private static void Add(ref double credit)
        {
            int i=10;
            credit = credit + i;
        }
        //返回多余的值
        //out侧重于在一个方法中可以返回多个不同类型
        public static bool IsLogin(string userName,string passWord, out string msg)
        {
            if (userName =="Alice"&&passWord =="1111")
                {
                    msg = "登录成功";
                    return true;
                    
                }
                else{
                    msg = "登录失败,请检查用户名和密码";
                    return false;
                }

        }

    }
}
